package com.web.music.portal.mvc;

import org.springframework.validation.Errors;
import org.springframework.validation.Validator;

import com.web.music.model.Genre;

public class GenreFormValidator implements Validator{

	public boolean supports(Class givenClass){
		return givenClass.equals(Genre.class);
	}

	public void validate(Object obj, Errors errors){
		Genre genre = (Genre)obj;

		if (genre == null){
			errors.reject("error.nullpointer", "Null data received");
		}
		else{
			if (genre.getName().equals("")){
				errors.rejectValue("name", "error.empty", "Name is required!"); 
			}
		}
	}
}